﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Sql;
using System.Data.SqlClient;

using System.Security.Cryptography;
using System.Net;
using System.IO;
using System.Data.Common;
using MySql.Data.MySqlClient;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;
using QiHe.Notice;
using QiHe.EQ;
using QiHe.UserManage;
using QiHe.Office.Tool;



namespace QiHe
{
    public partial class MainForm : Form
    {
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
       
        DataSet ds1, ds2, ds13, ds14;

        public MainForm()
        {
            if (IsConnectInternet())
            {

                InitializeComponent();
                DataTemp.HSPID = "1";
                DataTemp.HSPName = "中国医科大学";
                DataTemp.UserChineseName = "测试管理员";
                loadchart1();
                loadchart2();
                loadchart3();



                BackgroundWorker backgroundworker = new BackgroundWorker();
                backgroundworker.DoWork += new DoWorkEventHandler(back_DoWork);
                backgroundworker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(back_RunWorkerCompleted);
                backgroundworker.RunWorkerAsync();
            }
            else
            {
                InitializeComponent();
                MessageBox.Show("请检查网络！");


            }







        }



        void back_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            ListBind();
           





        }

        void back_DoWork(object sender, DoWorkEventArgs e)
        {





            loadlist1();
            loadlist2();
           loadlist3();
          //  loadlist4();


        }










        private void ListBind()
        {

            label1.Visible = false;
            linkLabel1.Text = ds1.Tables[0].Rows[0][1].ToString();
            if (ds1.Tables[0].Rows.Count > 1)
                linkLabel2.Text = ds1.Tables[0].Rows[1][1].ToString();
            if (ds1.Tables[0].Rows.Count > 2)
                linkLabel3.Text = ds1.Tables[0].Rows[2][1].ToString();
            if (ds1.Tables[0].Rows.Count > 3)
                linkLabel4.Text = ds1.Tables[0].Rows[3][1].ToString();
            if (ds1.Tables[0].Rows.Count > 4)
                linkLabel5.Text = ds1.Tables[0].Rows[4][1].ToString();



            label2.Visible = false;
            if (ds2.Tables[0].Rows.Count > 0)
                linkLabel10.Text = ds2.Tables[0].Rows[0][8].ToString().Trim() + "  " + ds2.Tables[0].Rows[0][11].ToString() ;
            if (ds2.Tables[0].Rows.Count > 1)
                linkLabel9.Text = ds2.Tables[0].Rows[1][8].ToString().Trim() + "  " + ds2.Tables[0].Rows[1][11].ToString() ;
            if (ds2.Tables[0].Rows.Count > 2)
                linkLabel8.Text = ds2.Tables[0].Rows[2][8].ToString().Trim() + "  " + ds2.Tables[0].Rows[2][11].ToString() ;
            if (ds2.Tables[0].Rows.Count > 3)
                linkLabel7.Text = ds2.Tables[0].Rows[3][8].ToString().Trim() + "  " + ds2.Tables[0].Rows[3][11].ToString() ;
            if (ds2.Tables[0].Rows.Count > 4)
                linkLabel6.Text = ds2.Tables[0].Rows[4][8].ToString().Trim() + "  " + ds2.Tables[0].Rows[4][11].ToString();
            
                        label3.Visible = false;
                        if (ds13.Tables[0].Rows.Count > 0)
                            linkLabel15.Text = ds13.Tables[0].Rows[0][8].ToString().Trim() + "  " + ds13.Tables[0].Rows[0][9].ToString();
                        if (ds13.Tables[0].Rows.Count > 1)
                            linkLabel14.Text = ds13.Tables[0].Rows[1][8].ToString().Trim() + "  " + ds13.Tables[0].Rows[1][9].ToString();
                        if (ds13.Tables[0].Rows.Count > 2)
                            linkLabel13.Text = ds13.Tables[0].Rows[2][8].ToString().Trim() + "  " + ds13.Tables[0].Rows[2][9].ToString() ;
                        if (ds13.Tables[0].Rows.Count > 3)
                            linkLabel12.Text = ds13.Tables[0].Rows[3][8].ToString().Trim() + "  " + ds13.Tables[0].Rows[3][9].ToString() ;
                        if (ds13.Tables[0].Rows.Count > 4)
                            linkLabel11.Text = ds13.Tables[0].Rows[4][8].ToString().Trim() + "  " + ds13.Tables[0].Rows[4][9].ToString();


            /*

                        label4.Visible = false;
                        if (ds14.Tables[0].Rows.Count > 0)
                            linkLabel20.Text = ds14.Tables[0].Rows[0][8].ToString().Trim() + "  " + ds14.Tables[0].Rows[0][11].ToString() + ":" + ds14.Tables[0].Rows[0][12].ToString() + "分";
                        if (ds14.Tables[0].Rows.Count > 1)
                            linkLabel19.Text = ds14.Tables[0].Rows[1][8].ToString().Trim() + "  " + ds14.Tables[0].Rows[1][11].ToString() + ":" + ds14.Tables[0].Rows[1][12].ToString() + "分";
                        if (ds14.Tables[0].Rows.Count > 2)
                            linkLabel18.Text = ds14.Tables[0].Rows[2][8].ToString().Trim() + "  " + ds14.Tables[0].Rows[2][11].ToString() + ":" + ds14.Tables[0].Rows[2][12].ToString() + "分";
                        if (ds14.Tables[0].Rows.Count > 3)
                            linkLabel17.Text = ds14.Tables[0].Rows[3][8].ToString().Trim() + "  " + ds14.Tables[0].Rows[3][11].ToString() + ":" + ds14.Tables[0].Rows[3][12].ToString() + "分";
                        if (ds14.Tables[0].Rows.Count > 4)
                            linkLabel16.Text = ds14.Tables[0].Rows[4][8].ToString().Trim() + "  " + ds14.Tables[0].Rows[4][11].ToString() + ":" + ds14.Tables[0].Rows[4][12].ToString() + "分";


                        */
        }


        private void loadlist1()
        {
            if (IsConnectInternet())
            {

                DBS db = new DBS();
                ds1 = db.Message_List_Top_5();
            }


        }
        private void loadlist2()
        {
            
            DBS db = new DBS();
            ds2 = db.RPlist_Top5();

        }
        private void loadlist3()
        {
            DBS db = new DBS();
            ds13 = db.RPlist_UnProv_Top5();

        }
        private void loadlist4()
        {
            ds14 = new DataSet();
            MedEQ.Service1 sop = new MedEQ.Service1();
            ds14 = sop.RPlist_Vote_Top5("1");

        }
        private void loadchart1()
        {
            //chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
            Series series = chart1.Series[0];
            // 画样条曲线（Spline）           
            series.ChartType = SeriesChartType.Spline;
            // 线宽2个像素          
            series.BorderWidth = 2;
            // 线的颜色：红色           
            series.Color = System.Drawing.Color.Red;
            // 图示上的文字           
            series.LegendText = "维修统计";
            // 准备数据        
            float[] values = { 95, 30, 20, 23, 60 };
            // 在chart中显示数据        
            int x = 0;
            foreach (float v in values)
            {
                series.Points.AddXY(x, v);
                x++;
            }
            // 设置显示范围         
            ChartArea chartArea = chart1.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 12;
            chartArea.AxisY.Minimum = 0d;
            chartArea.AxisY.Maximum = 250d;


        }
        private void loadchart2()
        {

            Series series = chart2.Series[0];
            chart2.ChartAreas[0].Area3DStyle.Enable3D = true;
            // 画样条曲线（Spline）           
            series.ChartType = SeriesChartType.Column;
            // 线宽2个像素          
            series.BorderWidth = 2;
            // 线的颜色：红色           
            series.Color = System.Drawing.Color.Blue;
            // 图示上的文字           
            series.LegendText = "维修费统计";

            // 准备数据        
            float[] values = { 28, 30, 20, 23, 60 };

            // 在chart中显示数据        
            int y = 0;
            foreach (float v in values)
            {
                series.Points.AddXY(y, v);
                y++;
            }
            // 设置显示范围         
            ChartArea chartArea = chart2.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 12;
            chartArea.AxisY.Minimum = 0d;
            chartArea.AxisY.Maximum = 100d;


        }
        private void loadchart3()
        {
            Series series = chart3.Series[0];
            chart3.ChartAreas[0].Area3DStyle.Enable3D = true;
            // 画样条曲线（Spline）           
            series.ChartType = SeriesChartType.Column;
            // 线宽2个像素          
            series.BorderWidth = 2;
            // 线的颜色：红色           
            series.Color = System.Drawing.Color.Blue;
            // 图示上的文字           
            series.LegendText = "费用排名";

            // 准备数据        
            float[] values = { 28, 30, 20, 23, 60 };

            // 在chart中显示数据        
            int y = 0;
            foreach (float v in values)
            {
                series.Points.AddXY(y, v);
                y++;
            }
            // 设置显示范围         
            ChartArea chartArea = chart3.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 12;
            chartArea.AxisY.Minimum = 0d;
            chartArea.AxisY.Maximum = 100d;

        }
        private void button1_Click(object sender, EventArgs e)
        {
            EQ_List eq = new EQ_List();
            eq.ShowDialog();
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Task_List eq = new Task_List();
            eq.ShowDialog();
        }

        private void 设备明细ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EQ_List el = new EQ_List();
            el.ShowDialog();
        }

        private void 任务列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_List tl = new Task_List();
            tl.ShowDialog();
        }

        private void 未审批任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Edit te = new Task_Edit();
            te.ShowDialog();
        }










        private void 设备明细ToolStripMenuItem_Click_2(object sender, EventArgs e)
        {
            EQ_List eq = new EQ_List();
            eq.ShowDialog();
        }

        private void 任务黑板ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_List eq = new Task_List();
            eq.ShowDialog();
        }

        private void 已完成任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Edit te = new Task_Edit();
            te.ShowDialog();
        }

        private void skinLabel1_Click(object sender, EventArgs e)
        {
            Task_Unfinish te = new Task_Unfinish();
            te.ShowDialog();
        }

        private void skinLabel6_Click(object sender, EventArgs e)
        {
            loadlist2();
            ListBind();
        }

        private void skinLabel5_Click(object sender, EventArgs e)
        {
            loadlist3();
            ListBind();
        }

        private void MainForm_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized) //判断是否最小化
            {
                this.ShowInTaskbar = false; //不显示在系统任务栏
                notifyIcon1.Visible = true; //托盘图标可见
            }
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.Show();
                this.WindowState = FormWindowState.Normal;
                notifyIcon1.Visible = false;
                this.ShowInTaskbar = true;
            }

        }

        
       
        public static bool IsConnectInternet()
        {
            int Description = 0;
            return InternetGetConnectedState(Description, 0);
        }

        private void 任务审批ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_Task a = new Add_Task("000000");
            a.ShowDialog();
        }

        private void skinLabel7_Click(object sender, EventArgs e)
        {
            ListBind();
        }

        private void skinLabel8_Click(object sender, EventArgs e)
        {
            loadlist4();
            ListBind();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

        private void linkLabel10_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unfinish ti = new Task_Unfinish();
            ti.ShowDialog();
        }

        private void linkLabel9_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unfinish ti = new Task_Unfinish();
            ti.ShowDialog();
        }

        private void linkLabel8_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unfinish ti = new Task_Unfinish();
            ti.ShowDialog();
        }

        private void linkLabel7_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unfinish ti = new Task_Unfinish();
            ti.ShowDialog();
        }

        private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unfinish ti = new Task_Unfinish();
            ti.ShowDialog();
        }

        private void linkLabel15_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void linkLabel14_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void linkLabel13_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void linkLabel12_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void linkLabel11_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void 审批管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void 待审批任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void 已审批任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Approved_List ti = new Task_Approved_List();
            ti.ShowDialog();
        }

        private void pMToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Unaaprove ti = new Task_Unaaprove();
            ti.ShowDialog();
        }

        private void 执行中计划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Approved_List ti = new Task_Approved_List();
            ti.ShowDialog();
        }

        private void 未完成任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_Unfinish ti = new Task_Unfinish();
            ti.ShowDialog();
        }

        private void 生成本月PMToolStripMenuItem_Click(object sender, EventArgs e)
        {
          
        }

        private void 未完成PMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PM_Task_Creat ti = new PM_Task_Creat();
            ti.ShowDialog();
        }

        private void pM设定ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Set_PM_Dept ti = new Set_PM_Dept();
            ti.ShowDialog();
        }

        private void pMToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            PM_Unfinish_List ti = new PM_Unfinish_List();
            ti.ShowDialog();
        }

        private void pM模板管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            PM_TPL_List ti = new PM_TPL_List();
            ti.ShowDialog();
        
        }

        private void 通知列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Notice_List ti = new Notice_List();
            ti.ShowDialog();
        }

        private void 添加通知ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_Notice ti = new Add_Notice();
            ti.ShowDialog();
        }

        private void 添加临时设备ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_TempEQ ti = new Add_TempEQ();
            ti.ShowDialog();
        }

        private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 数据统计ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 添加用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_EGN ti = new Add_EGN();
            ti.ShowDialog();
        }

        private void 用户科室管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            User_Depts_List ti = new User_Depts_List();
            ti.ShowDialog();
            
        }

        private void 倒入设备ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }
            
        }
    }

     
